package com.yunhui.util;

public class WGHStringUtils {
	/**
	 * 判断是否为空
	 * @param resx_string
	 * @return
	 */
	public static boolean isBank(String resx_string){
		
		if(resx_string.trim()!=null && "".equals(resx_string.trim())){
			return false;
		}
		return true;
	}
	

	public static String objToString(Object obj) {
		String str = "";
		if (obj != null) {
			str = obj.toString().trim();
		}
		return str;
	}

	public static Integer objToInteger(Object obj) {
		String str = "";
		if (obj != null) {
			str = obj.toString().trim();
		}
		if (str == null || "NaN".equalsIgnoreCase(str) || str.trim().length() == 0) {
			return 0;
		}
		if (isNumber(str) == false) {
			return 0;
		}
		return Integer.parseInt(str);
	}

	public static boolean objToBoolean(Object obj) {
		String str = "";
		if (obj != null) {
			str = obj.toString().trim();
		}
		if (str == null || str.trim().length() == 0) {
			return false;
		}

		return Boolean.parseBoolean(str);
	}

	public static boolean isNumber(String str) {
		if (str == null || (str = str.trim()).length() == 0) {
			return false;
		}
		return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
	}

	/*
	 * 判断字符串是否既不为null也不为空字符串
	 */
	public static boolean isNotBlank(String target) {
		return !isBlank(target);
	}

	public static boolean isBlank(String target) {
		if (target == null || target.trim().length() == 0) {
			return true;
		}
		return false;
	}

	public static boolean isNumeric(String target) {
		if (target == null) {
			return false;
		}
		int sz = target.length();
		for (int i = 0; i < sz; ++i) {
			if (!Character.isDigit(target.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	public static Boolean toBooleanObject(String str) {
		if ("true".equalsIgnoreCase(str))
			return Boolean.TRUE;
		if ("false".equalsIgnoreCase(str))
			return Boolean.FALSE;
		if ("on".equalsIgnoreCase(str))
			return Boolean.TRUE;
		if ("off".equalsIgnoreCase(str))
			return Boolean.FALSE;
		if ("yes".equalsIgnoreCase(str))
			return Boolean.TRUE;
		if ("no".equalsIgnoreCase(str)) {
			return Boolean.FALSE;
		}

		return null;
	}

	public static boolean matches(Object obj, String condition) {
		String string = "";
		if (obj != null) {
			string = obj.toString();
		}
		// 自定义拦截规则
		if ("LIKE_RULE".equals(condition)) {
			boolean success = true;
			// 如果有多个匹配字符
			String[] ruleArray = condition.split(";|；");
			for (int i = 0; i < ruleArray.length; i++) {
				// 去除所有空格，匹配规则
				int index = string.replaceAll(" +", "").trim().indexOf(ruleArray[i]);
				if (index != -1) {
					success = false;
				}
			}
			return success;
		} else {
			return string.matches(condition);
		}
	}
}
